
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>django.apps.config &#8212; Django 2.2.12.dev20200304094918 documentation</title>
    <link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../../_static/language_data.js"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />



 
<script type="text/javascript" src="../../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../../ref/templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../../index.html">Django 2.2.12.dev20200304094918 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../../index.html">Home</a>  |
        <a title="Table of contents" href="../../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../../genindex.html">Index</a>  |
        <a title="Module index" href="../../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    <a href="../../index.html" title="Module code" accesskey="U">up</a></div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="_modules-django-apps-config">
            
  <h1>Source code for django.apps.config</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">importlib</span> <span class="k">import</span> <span class="n">import_module</span>

<span class="kn">from</span> <span class="nn">django.core.exceptions</span> <span class="k">import</span> <span class="n">ImproperlyConfigured</span>
<span class="kn">from</span> <span class="nn">django.utils.module_loading</span> <span class="k">import</span> <span class="n">module_has_submodule</span>

<span class="n">MODELS_MODULE_NAME</span> <span class="o">=</span> <span class="s1">&#39;models&#39;</span>


<div class="viewcode-block" id="AppConfig"><a class="viewcode-back" href="../../../ref/applications.html#django.apps.AppConfig">[docs]</a><span class="k">class</span> <span class="nc">AppConfig</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;Class representing a Django application and its configuration.&quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">app_name</span><span class="p">,</span> <span class="n">app_module</span><span class="p">):</span>
        <span class="c1"># Full Python path to the application e.g. &#39;django.contrib.admin&#39;.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">app_name</span>

        <span class="c1"># Root module for the application e.g. &lt;module &#39;django.contrib.admin&#39;</span>
        <span class="c1"># from &#39;django/contrib/admin/__init__.py&#39;&gt;.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">module</span> <span class="o">=</span> <span class="n">app_module</span>

        <span class="c1"># Reference to the Apps registry that holds this AppConfig. Set by the</span>
        <span class="c1"># registry when it registers the AppConfig instance.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">apps</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="c1"># The following attributes could be defined at the class level in a</span>
        <span class="c1"># subclass, hence the test-and-set pattern.</span>

        <span class="c1"># Last component of the Python path to the application e.g. &#39;admin&#39;.</span>
        <span class="c1"># This value must be unique across a Django project.</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s1">&#39;label&#39;</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">label</span> <span class="o">=</span> <span class="n">app_name</span><span class="o">.</span><span class="n">rpartition</span><span class="p">(</span><span class="s2">&quot;.&quot;</span><span class="p">)[</span><span class="mi">2</span><span class="p">]</span>

        <span class="c1"># Human-readable name for the application e.g. &quot;Admin&quot;.</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s1">&#39;verbose_name&#39;</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">verbose_name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">label</span><span class="o">.</span><span class="n">title</span><span class="p">()</span>

        <span class="c1"># Filesystem path to the application directory e.g.</span>
        <span class="c1"># &#39;/path/to/django/contrib/admin&#39;.</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s1">&#39;path&#39;</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">path</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_path_from_module</span><span class="p">(</span><span class="n">app_module</span><span class="p">)</span>

        <span class="c1"># Module containing models e.g. &lt;module &#39;django.contrib.admin.models&#39;</span>
        <span class="c1"># from &#39;django/contrib/admin/models.py&#39;&gt;. Set by import_models().</span>
        <span class="c1"># None if the application doesn&#39;t have a models module.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">models_module</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="c1"># Mapping of lowercase model names to model classes. Initially set to</span>
        <span class="c1"># None to prevent accidental access before import_models() runs.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">models</span> <span class="o">=</span> <span class="kc">None</span>

    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s1">&#39;&lt;</span><span class="si">%s</span><span class="s1">: </span><span class="si">%s</span><span class="s1">&gt;&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">label</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_path_from_module</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">module</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Attempt to determine app&#39;s filesystem path from its module.&quot;&quot;&quot;</span>
        <span class="c1"># See #21874 for extended discussion of the behavior of this method in</span>
        <span class="c1"># various cases.</span>
        <span class="c1"># Convert paths to list because Python&#39;s _NamespacePath doesn&#39;t support</span>
        <span class="c1"># indexing.</span>
        <span class="n">paths</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">getattr</span><span class="p">(</span><span class="n">module</span><span class="p">,</span> <span class="s1">&#39;__path__&#39;</span><span class="p">,</span> <span class="p">[]))</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">paths</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">filename</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">module</span><span class="p">,</span> <span class="s1">&#39;__file__&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">filename</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">paths</span> <span class="o">=</span> <span class="p">[</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">filename</span><span class="p">)]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c1"># For unknown reasons, sometimes the list returned by __path__</span>
                <span class="c1"># contains duplicates that must be removed (#25246).</span>
                <span class="n">paths</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">paths</span><span class="p">))</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">paths</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">ImproperlyConfigured</span><span class="p">(</span>
                <span class="s2">&quot;The app module </span><span class="si">%r</span><span class="s2"> has multiple filesystem locations (</span><span class="si">%r</span><span class="s2">); &quot;</span>
                <span class="s2">&quot;you must configure this app with an AppConfig subclass &quot;</span>
                <span class="s2">&quot;with a &#39;path&#39; class attribute.&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">module</span><span class="p">,</span> <span class="n">paths</span><span class="p">))</span>
        <span class="k">elif</span> <span class="ow">not</span> <span class="n">paths</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">ImproperlyConfigured</span><span class="p">(</span>
                <span class="s2">&quot;The app module </span><span class="si">%r</span><span class="s2"> has no filesystem location, &quot;</span>
                <span class="s2">&quot;you must configure this app with an AppConfig subclass &quot;</span>
                <span class="s2">&quot;with a &#39;path&#39; class attribute.&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">module</span><span class="p">,))</span>
        <span class="k">return</span> <span class="n">paths</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">create</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">entry</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Factory that creates an app config from an entry in INSTALLED_APPS.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="c1"># If import_module succeeds, entry is a path to an app module,</span>
            <span class="c1"># which may specify an app config class with default_app_config.</span>
            <span class="c1"># Otherwise, entry is a path to an app config class or an error.</span>
            <span class="n">module</span> <span class="o">=</span> <span class="n">import_module</span><span class="p">(</span><span class="n">entry</span><span class="p">)</span>

        <span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
            <span class="c1"># Track that importing as an app module failed. If importing as an</span>
            <span class="c1"># app config class fails too, we&#39;ll trigger the ImportError again.</span>
            <span class="n">module</span> <span class="o">=</span> <span class="kc">None</span>

            <span class="n">mod_path</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">cls_name</span> <span class="o">=</span> <span class="n">entry</span><span class="o">.</span><span class="n">rpartition</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)</span>

            <span class="c1"># Raise the original exception when entry cannot be a path to an</span>
            <span class="c1"># app config class.</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">mod_path</span><span class="p">:</span>
                <span class="k">raise</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="c1"># If this works, the app module specifies an app config class.</span>
                <span class="n">entry</span> <span class="o">=</span> <span class="n">module</span><span class="o">.</span><span class="n">default_app_config</span>
            <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
                <span class="c1"># Otherwise, it simply uses the default app config class.</span>
                <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">entry</span><span class="p">,</span> <span class="n">module</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">mod_path</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">cls_name</span> <span class="o">=</span> <span class="n">entry</span><span class="o">.</span><span class="n">rpartition</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)</span>

        <span class="c1"># If we&#39;re reaching this point, we must attempt to load the app config</span>
        <span class="c1"># class located at &lt;mod_path&gt;.&lt;cls_name&gt;</span>
        <span class="n">mod</span> <span class="o">=</span> <span class="n">import_module</span><span class="p">(</span><span class="n">mod_path</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="bp">cls</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">mod</span><span class="p">,</span> <span class="n">cls_name</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">module</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="c1"># If importing as an app module failed, check if the module</span>
                <span class="c1"># contains any valid AppConfigs and show them as choices.</span>
                <span class="c1"># Otherwise, that error probably contains the most informative</span>
                <span class="c1"># traceback, so trigger it again.</span>
                <span class="n">candidates</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span>
                    <span class="nb">repr</span><span class="p">(</span><span class="n">name</span><span class="p">)</span> <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">candidate</span> <span class="ow">in</span> <span class="n">mod</span><span class="o">.</span><span class="vm">__dict__</span><span class="o">.</span><span class="n">items</span><span class="p">()</span>
                    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">candidate</span><span class="p">,</span> <span class="nb">type</span><span class="p">)</span> <span class="ow">and</span>
                    <span class="nb">issubclass</span><span class="p">(</span><span class="n">candidate</span><span class="p">,</span> <span class="n">AppConfig</span><span class="p">)</span> <span class="ow">and</span>
                    <span class="n">candidate</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">AppConfig</span>
                <span class="p">)</span>
                <span class="k">if</span> <span class="n">candidates</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="n">ImproperlyConfigured</span><span class="p">(</span>
                        <span class="s2">&quot;&#39;</span><span class="si">%s</span><span class="s2">&#39; does not contain a class &#39;</span><span class="si">%s</span><span class="s2">&#39;. Choices are: </span><span class="si">%s</span><span class="s2">.&quot;</span>
                        <span class="o">%</span> <span class="p">(</span><span class="n">mod_path</span><span class="p">,</span> <span class="n">cls_name</span><span class="p">,</span> <span class="s1">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">candidates</span><span class="p">))</span>
                    <span class="p">)</span>
                <span class="n">import_module</span><span class="p">(</span><span class="n">entry</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span>

        <span class="c1"># Check for obvious errors. (This check prevents duck typing, but</span>
        <span class="c1"># it could be removed if it became a problem in practice.)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">issubclass</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">AppConfig</span><span class="p">):</span>
            <span class="k">raise</span> <span class="n">ImproperlyConfigured</span><span class="p">(</span>
                <span class="s2">&quot;&#39;</span><span class="si">%s</span><span class="s2">&#39; isn&#39;t a subclass of AppConfig.&quot;</span> <span class="o">%</span> <span class="n">entry</span><span class="p">)</span>

        <span class="c1"># Obtain app name here rather than in AppClass.__init__ to keep</span>
        <span class="c1"># all error checking for entries in INSTALLED_APPS in one place.</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">app_name</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="n">name</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">ImproperlyConfigured</span><span class="p">(</span>
                <span class="s2">&quot;&#39;</span><span class="si">%s</span><span class="s2">&#39; must supply a name attribute.&quot;</span> <span class="o">%</span> <span class="n">entry</span><span class="p">)</span>

        <span class="c1"># Ensure app_name points to a valid module.</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">app_module</span> <span class="o">=</span> <span class="n">import_module</span><span class="p">(</span><span class="n">app_name</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">ImproperlyConfigured</span><span class="p">(</span>
                <span class="s2">&quot;Cannot import &#39;</span><span class="si">%s</span><span class="s2">&#39;. Check that &#39;</span><span class="si">%s</span><span class="s2">.</span><span class="si">%s</span><span class="s2">.name&#39; is correct.&quot;</span> <span class="o">%</span> <span class="p">(</span>
                    <span class="n">app_name</span><span class="p">,</span> <span class="n">mod_path</span><span class="p">,</span> <span class="n">cls_name</span><span class="p">,</span>
                <span class="p">)</span>
            <span class="p">)</span>

        <span class="c1"># Entry is a path to an app config class.</span>
        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">app_name</span><span class="p">,</span> <span class="n">app_module</span><span class="p">)</span>

<div class="viewcode-block" id="AppConfig.get_model"><a class="viewcode-back" href="../../../ref/applications.html#django.apps.AppConfig.get_model">[docs]</a>    <span class="k">def</span> <span class="nf">get_model</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model_name</span><span class="p">,</span> <span class="n">require_ready</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return the model with the given case-insensitive model_name.</span>

<span class="sd">        Raise LookupError if no model exists with this name.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">require_ready</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">apps</span><span class="o">.</span><span class="n">check_models_ready</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">apps</span><span class="o">.</span><span class="n">check_apps_ready</span><span class="p">()</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">models</span><span class="p">[</span><span class="n">model_name</span><span class="o">.</span><span class="n">lower</span><span class="p">()]</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">LookupError</span><span class="p">(</span>
                <span class="s2">&quot;App &#39;</span><span class="si">%s</span><span class="s2">&#39; doesn&#39;t have a &#39;</span><span class="si">%s</span><span class="s2">&#39; model.&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">label</span><span class="p">,</span> <span class="n">model_name</span><span class="p">))</span></div>

<div class="viewcode-block" id="AppConfig.get_models"><a class="viewcode-back" href="../../../ref/applications.html#django.apps.AppConfig.get_models">[docs]</a>    <span class="k">def</span> <span class="nf">get_models</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">include_auto_created</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">include_swapped</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return an iterable of models.</span>

<span class="sd">        By default, the following models aren&#39;t included:</span>

<span class="sd">        - auto-created models for many-to-many relations without</span>
<span class="sd">          an explicit intermediate table,</span>
<span class="sd">        - models that have been swapped out.</span>

<span class="sd">        Set the corresponding keyword argument to True to include such models.</span>
<span class="sd">        Keyword arguments aren&#39;t documented; they&#39;re a private API.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">apps</span><span class="o">.</span><span class="n">check_models_ready</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">model</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">models</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">model</span><span class="o">.</span><span class="n">_meta</span><span class="o">.</span><span class="n">auto_created</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">include_auto_created</span><span class="p">:</span>
                <span class="k">continue</span>
            <span class="k">if</span> <span class="n">model</span><span class="o">.</span><span class="n">_meta</span><span class="o">.</span><span class="n">swapped</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">include_swapped</span><span class="p">:</span>
                <span class="k">continue</span>
            <span class="k">yield</span> <span class="n">model</span></div>

    <span class="k">def</span> <span class="nf">import_models</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c1"># Dictionary of models for this app, primarily maintained in the</span>
        <span class="c1"># &#39;all_models&#39; attribute of the Apps this AppConfig is attached to.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">models</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">apps</span><span class="o">.</span><span class="n">all_models</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">label</span><span class="p">]</span>

        <span class="k">if</span> <span class="n">module_has_submodule</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">module</span><span class="p">,</span> <span class="n">MODELS_MODULE_NAME</span><span class="p">):</span>
            <span class="n">models_module_name</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">.</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">MODELS_MODULE_NAME</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">models_module</span> <span class="o">=</span> <span class="n">import_module</span><span class="p">(</span><span class="n">models_module_name</span><span class="p">)</span>

<div class="viewcode-block" id="AppConfig.ready"><a class="viewcode-back" href="../../../ref/applications.html#django.apps.AppConfig.ready">[docs]</a>    <span class="k">def</span> <span class="nf">ready</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Override this method in subclasses to run code when Django starts.</span>
<span class="sd">        &quot;&quot;&quot;</span></div></div>
</pre></div>

          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Mar 04, 2020</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    <a href="../../index.html" title="Module code" accesskey="U">up</a></div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>